local likeSetKey = KEYS[1]
local noteLikeSetKey = KEYS[2]
local noteUnlikeSetKey = KEYS[3]
local userId = ARGV[1]
local r = 0

if redis.call('SISMEMBER', likeSetKey, userId) == 1 then
    return 1
end

if redis.call('SISMEMBER', noteUnlikeSetKey, userId) == 1 then
    r = redis.call('SREM', noteUnlikeSetKey, userId)
end

if redis.call('SISMEMBER', noteLikeSetKey, userId) == 1 then
    return 1
else
    if r == 0 then
        redis.call('SADD', noteLikeSetKey, userId)
    end
end


redis.call('SADD', likeSetKey, userId)
return 1
